
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
#endregion

namespace jaam_butters
{
    /// <summary>
    /// This is A game component that is notified when it needs to draw itself. 
    /// It implements IDrawable.
    /// </summary>
    public partial class Butters : DrawableGameComponent
    {
        SpriteBatch spriteBatch;
        Texture2D sprite;
        Texture2D helpExpand;
        SpriteFont font;
        Rectangle spriteDest;
        Rectangle textDest;
        bool hidden;
        string textContent;
        Vector2 stringDims;
        MouseState old;
        int hiddenPos;
        public Butters(Game game,SpriteBatch sb)
            : base(game)
        {
            // TODO: Construct any child components here
            hidden = true;
            textContent = "Help  ";
            old = Mouse.GetState();
            hiddenPos = game.Window.ClientBounds.Width - 150;
            LoadContent();
            spriteBatch = sb;
        }

        /// <summary>
        /// Load graphics content specific to your component.
        /// </summary>
        protected override void LoadContent()
        {
            // TODO: Load any ResourceManagementMode.Manual content
            sprite = Game.Content.Load<Texture2D>("wizurdbutters");
            helpExpand = Game.Content.Load<Texture2D>("helpExpand");
            font = Game.Content.Load<SpriteFont>("myFont");
            //spriteBatch = new SpriteBatch(Game.GraphicsDevice);

            spriteDest = new Rectangle(hiddenPos, 0, sprite.Width, sprite.Height);
            stringDims = font.MeasureString(textContent);
            textDest = new Rectangle(Game.Window.ClientBounds.Width-(int)stringDims.X-150, 0,(int)stringDims.X,(int)stringDims.Y);
            //base.LoadContent();
        }


        /// <summary>
        /// Allows the component to run logic such as updating the world,
        /// checking for collisions, gathering input and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {

            // TODO: Add your update logic here
            MouseState current = Mouse.GetState();
            if (current.LeftButton == ButtonState.Pressed && current.LeftButton != old.LeftButton)
            {
                if (textDest.Contains(current.X,current.Y))
                {
                    if (textContent == "Help  ")
                    {
                        hidden = false;
                        textContent = "Close";
                    }
                    else
                    {
                        hidden = true;
                        textContent = "Help  ";
                    }
                }
            }
            old = current;
            int offset = 280;
            if (!hidden)
            {
                textDest.X += (hiddenPos - (int)stringDims.X - textDest.X - offset) / 8;
                spriteDest.X += (hiddenPos - spriteDest.X - offset) / 8;
            }
            else
            {
                textDest.X += (hiddenPos - (int)stringDims.X - textDest.X) / 8;
                spriteDest.X += (hiddenPos - spriteDest.X) / 8;
            }
            //base.Update(gameTime);
        }


        /// <summary>
        /// This is called when the component should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Draw(GameTime gameTime)
        {
            
            // TODO: Add your drawing code here
            //spriteBatch.Begin();
            spriteBatch.Draw(helpExpand, textDest, Color.White);
            spriteBatch.DrawString(font, textContent, new Vector2(textDest.X , textDest.Y), Color.Black);
            spriteBatch.Draw(sprite, spriteDest, Color.White);
            //spriteBatch.End();
            //base.Draw(gameTime);
        }
    }
}


